package com.ws.universal.tools.utils;

import android.app.Activity;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.Signature;
import android.util.Base64;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class KeystoreUtils {
    //KeyHash用于配置第三方登录
    public static void checkKeyStoreHash(Activity activity) {
        try {
            PackageInfo info = activity.getPackageManager().getPackageInfo(AppUtils.getAppPackageName(), PackageManager.GET_SIGNATURES);

            for (Signature sign : info.signatures) {
                MessageDigest md = MessageDigest.getInstance("SHA");
                md.update(sign.toByteArray());
                LogcatUtils.e("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
            }
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
            LogcatUtils.e("KeyHash:", "error " + e.toString());
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            LogcatUtils.e("KeyHash:", "error " + e.toString());
        }
    }
}
